/// <source>
/// <name>org.cote.js.xml</name>
/// <project>
/// 	<name>Engine for Web Applications</name>
/// 	<url-title>Engine for Web Applications Project</url-title>
/// 	<url>/projects/engine/</url>
/// </project>
///

/*
	libXmlRequest
	Source: org.cote.js.xml
	Copyright 2002 - 2008. All Rights Reserved.
	Version: %FILE_VERSION%
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
*/

/*
	REMARKS

		The org, org.cote, and org.cote.js defs are a literal translation from the Engine project.
		The structure is left intact for compatibility.
	
		The package structure is considered part of the branding and copyright; do not alter it.


	BROWSER SUPPORT
		
		Mozilla-based browsers (eg: Mozilla, Firebird, NS 7)
			XSL and XPath supported as of 1.2

		Internet Explorer 5.01 and later
			MSXML Support is defined as MSXML2.XMLHTTP.3.0

		Safari 1.0.3: XMLHttpRequest, no XPath, no XSL




		Opera 8: XMLHttpRequest, no XPath, no XSL

		Konqueror: No / unknown

	SERVER SUPPORT NOTE
	
		Some Application Servers such as Perl and PhP expect XML Posts to be set with a specific content type.
		The default encoding for version SPEC-1.5.1.0909.2005 is "text/xml".
		It may be necessary to specify "application/x-www-form-urlencoded" or "multipart/form-data" for posted XML data to be interpreted on the server.

	USAGE
	
		Synchronous GET:
			[xml_dom_object] = getXml(path);

			Example:
			var oXml = org.cote.js.xml.getXml("/Data/Test1.xml");

		Asynchronous GET:
			[int] = getXml(path,custom_handler,1,{optional_id});

			Example:
			function HandleXml(s,v){
				var oXml = v.xdom;
			}
			org.cote.js.xml.getXml("/Data/Test1.xml",HandleXml,1);
			
		Cached Asynchronous GET:
			[int] = getXml(path,custom_handler,1,request_id,1);
			
			Example:
			function HandleXml(s,v){
				var oXml = v.xdom;
			}
			org.cote.js.xml.getXml("/Data/Test1.xml",HandleXml,1,"cache-me",1);
			
		Synchronous POST:
			[xml_dom_object] = postXml(path,data);
			
			Example:
			
			var oPostThis = org.cote.js.xml.newXmlDocument("Request");
			var oData = oPostThis.createElement("data");
			oData.setAttribute("id","data-id");
			oData.setAttribute("value","data-value");
			oPostThis.documentElement.appendChild(oData);
			
			var oResponseXml = org.cote.js.xml.postXml("/Data/TestData.aspx",oPostThis);
			
		Asynchronous POST:
			[int] = postXml(path,data,custom_handler,1,{optional_id});
			
			Example:
			
			
			function HandleXml(s,v){
				var oResponseXml = v.xdom;
			}
			var oPostThis = org.cote.js.xml.newXmlDocument("Request");
			var oResponseXml = org.cote.js.xml.postXml("/Data/TestData.aspx",oPostThis,HandlePostXml,1);
			

		Notes:
			custom_handler, required for asynchronous requests, is invoked with two parameters:
			"onloadxml", and a generic object.  The object includes two properties:
			object.id is the request id, and object.xdom refers to the XML DOM.
			If the request fails, object.xdom will be null.
			
	INTERNAL NOTES
		
		The spec for XMLHttpRequest specifies that all handlers are cleared after each request.
		Therefore, the internal handlers are cleared after each request.  If not, they don't fire on subsequent requests.

	BUGS and BUG FIXES

		02/26/2009 : Update raw text handling
			Add better raw text handling for JSON support.  Include a few JSON hooks for convenience.
			

        04/23/2008 : IE 7 Fix for native XMLHttpRequest via FileSystem
            Add a special case for IE 7 support of local filesystem requests via XMLHttpRequest
            The resolution was to degrade to a DOM Document load.
	
	    04/17/2007 : Merge
	        Merge corrections between different versions of library.
	        Investigate issue with Mozilla posting on Vista to IIS 7

		11/15/2005 : Typo
			Fixed typo for asynchronous non-cached non-IE requests.

		10/10/2005 : Safari bug fixes
			Add corrections for Safari request header and creating new XML documents

		09/09/2005 : clearCache wasn't actually clearing the cache.		
			Some method cleanup required.
			
			The internal event handler, and therefore any custom event handler, for asynchronous calls that fail due to exceeding the pool size, was not being called.  This has been fixed.
			
		09/08/2005 : Improve support
			Improved support for Opera and Safari.

		06/17/2003 : Race condition occurs in multiple requests using the same request id
			Status: fixed
			
			XML Requests are stored in an array so as to keep track of the request for asynchronous and synchronous actions.
			A property on a request item is used for caching, if caching is enabled.

			Whether caching is enabled or the request is synchronous or asynchronous,
			a race condition ensues if multiple requests are made at the same time, with the same id.
			The bug is the first request is incomplete, and subsequent requests fail in cache request,
			or fail in the internal request handler.
			
			The solution was to tack on a unique back-up id if the same-id request is incomplete.
			This results in two requests for the same XML file, but the result is returned with the original request id.
			If caching is enabled, then the cache return the same-id request once the first request is finished.

			This was originally fixed only for cached, synchronous requests, but then expanded to included all requests.

		05/30/2003 : Event handler problem in Mozilla 1.4RC1
			Status: fixed; duplicate clean-up still open

			Latest Mozilla build, 1.4RC1 won't use the same event listener for the same object.
			Solution: add event listener at the time of the request, then strip it off later.
			
			This will also clean up the duplicate code for adding event listeners for pooled and non-pooled objects, which is pretty much the same.

		05/08/2003 : Event handler problem in IE
			Status: fixed; refer race-condition fix
			
			The IE sync bug cropped up again outside of the cached http feature.
			If the feature is turned off, it seems the requests can get
			stacked up (see Engine Demo #10 in IE), and cause the browser to hang
			or fail (see Moz) to completely load the XML.
			
			Multiple requests seem to be ok, up to an undetermined point.
			
			The feature should be left intact for heavy use anyway, but it is crucial to
			note because it then becomes a requirement for heavy use.

		12/28/2002
			Status: fixed
			
			Fixed bug in returnXmlHttpObjectToPool; this was causing a monster headache!



pseudo code for selectSingleNode / selectNodes

window.selectNodes = function (d,v,c){
  var elName = v.replace(/[^\w].*$/,'');
  elName = d.getElementsByTagName(elName);
  var attrToMatch = v.replace(/^.*@/,'').replace(/\s*=.*$/,'');
  var valToMatch = v.replace(/^[^']*'/,'').replace(/'.*$/,'');
  for(var i=0;elName[i];i++){if(elName[i].getAttribute(attrToMatch)==valToMatch){return [elName[i]];}}
  return [];
}
*/

Engine.Package("org.cote.js.xml");

/// <package>
/// 	<path>org.cote.js</path>
/// <library>engine</library>
///	<static-class>
///		<name>xml</name>
///		<version>%FILE_VERSION%</version>
///		<description>A library for making XMLHTTP Requests.</description>
/// 

/// <example>
/// <name>Synchronous GET</name>
/// <description>Make a synchronous request for an XML document.</description>
/// <syntax>[xml_dom_object] = getXml(path);</syntax>
/// <code>var oXml = org.cote.js.xml.getXml("/Data/Test1.xml");</code>
/// </example>

/// <example>
/// <name>Asynchronous GET</name>
/// <description>Make an asynchronous request for an XML document.</description>
/// <syntax>[int] = getXml(path,custom_handler,1,{optional_id});</syntax>
/// <code>function HandleXml(s,v){</code>
/// <code>   var oXml = v.xdom;</code>
/// <code>}</code>
/// <code>org.cote.js.xml.getXml("/Data/Test1.xml",HandleXml,1);</code>
/// </example>
			
/// <example>
/// <name>Cached Asynchronous GET</name>
/// <description>Asynchronously request an XML document, and cached the result for later referal.</description>
/// <syntax>[int] = getXml(path,custom_handler,1,request_id,1);</syntax>
/// <code>function HandleXml(s,v){</code>
/// <code>   var oXml = v.xdom;</code>
/// <code>}</code>
/// <code>org.cote.js.xml.getXml("/Data/Test1.xml",HandleXml,1,"cache-me",1);</code>
/// </example>

/// <example>
/// <name>Synchronous POST</name>
/// <description>Synchronously post data to the server.</description>
/// <syntax>[xml_dom_object] = postXml(path,data);</syntax>
/// <code>var oPostThis = org.cote.js.xml.newXmlDocument("Request");</code>
/// <code>var oData = oPostThis.createElement("data");</code>
/// <code>oData.setAttribute("id","data-id");</code>
/// <code>oData.setAttribute("value","data-value");</code>
/// <code>oPostThis.documentElement.appendChild(oData);</code>
/// <code>var oResponseXml = org.cote.js.xml.postXml("/Data/TestData.aspx",oPostThis);</code>
/// </example>

/// <example>
/// <name>Asynchronous POST</name>
/// <description>Asynchronously post data to the server.</description>
/// <syntax>[int] = postXml(path,data,custom_handler,1,{optional_id});</syntax>
/// <code>function HandleXml(s,v){</code>
/// <code>   var oResponseXml = v.xdom;</code>
/// <code>}</code>
/// <code>var oPostThis = org.cote.js.xml.newXmlDocument("Request");</code>
/// <code>var oResponseXml = org.cote.js.xml.postXml("/Data/TestData.aspx",oPostThis,HandlePostXml,1);</code>
/// </example>


/// <object private="1">
/// <name>XmlHttp</name>
/// <description>Object representing a pooled XMLHTTP resource</description>
/// <property name = "xml_object" type = "object">An XMLHttp object.</property>
/// <property name = "in_use" type = "boolean">Bit indicating whether the object is in use.</property>
/// <property name = "vid" type = "int">Integer identifying the variant object identifier.</property>
/// <property name = "handler" type = "function">Anonymous wrapper to invoke the internal readystate or complete handler for the specified identifier.</property>
/// </object>
///
/// <object>
/// <name>XmlObject</name>
/// <description>Object passed to the event handler following an XML request using <i>getXml</i> or <i>postXml</i>.</description>
/// <property name = "xdom" type = "XMLDocument">An XML Document object.</property>
/// <property name = "id" type = "String">Identifier used to distinguish the request for this XML Document from other requests.</property>
/// </object>
///

org.cote.js.xml={
	object_version:"%FILE_VERSION%",
	
	/// <property type = "String" get = "1" set = "1" default = "text/xml">
	/// <name>xml_content_type</name>
	/// <description>Specifies the content type to use posting data.</description>
	/// </property>
	xml_content_type:"text/xml",
	/// <property type = "String" get = "1" set = "1" default = "text/xml">
	/// <name>text_content_type</name>
	/// <description>Specifies the content type to use requesting and receiving text data (eg: JSON).</description>
	/// </property>
	text_content_type:"text/plain",

	
	/// <property type = "boolean" get = "1" set = "1">
	/// <name>auto_content_type</name>
	/// <description>Specifies whether to determine posted content type by included post value.</description>
	/// </property>
	auto_content_type:1,

	/// <property type = "String" get = "1" set = "1">
	/// <name>form_content_type</name>
	/// <description>Specifies the content type to use when auto_content_type is true and the post value is a string.</description>
	/// </property>
	form_content_type:"application/x-www-form-urlencoded",
/*
	_xml_request:null,
	_xml_request_id:null,
*/
	_xml_requests:[],
	_xml_requests_map:[],

	/// <property type = "String" get = "1" set = "1">
	/// <name>ax_http_control</name>
	/// <description>Specifies the name of the registered ActiveX control to use for XML requests.</description>
	/// </property>
	ax_http_control:"MSXML2.XMLHTTP.4.0",

	/// <property type = "String" get = "1" set = "1">
	/// <name>ax_http_control</name>
	/// <description>Specifies the name of the registered ActiveX control to use for XML requests.</description>
	/// </property>
	ax_dom_control:"MSXML.DOMDocument",

	/// <property type = "boolean" get = "1" set = "1">
	/// <name>gadget_mode</name>
	/// <description>Specifies whether the xml package is operating in a mode that better supports Windows Sidebar Gadgets.</description>
	/// </property>
	gadget_mode:0,
	/// <property type = "String" get = "1" set = "1">
	/// <name>gadget_control</name>
	/// <description>Specifies the name of the registered ActiveX control to use for XML requests when in Gadget mode.</description>
	/// </property>
	gadget_xml_control:"Core.Gadget.GadgetXmlHttp",
	/// <property type = "String" get = "1" set = "1">
	/// <name>gadget_base_path</name>
	/// <description>Specifies the base path to use when operating in Gadget mode.  The base path should be in the format of a file URI, such as <i>file:///c:/...</i>.</description>
	/// </property>
	gadget_base_path:0,
	base_path:0,

	%START_XML_CACHE%
	_xml_http_cache_enabled:%XML_HTTP_CACHE_ENABLED%,

	/// <method>
	/// <name>setCacheEnabled</name>
	/// <param name="b" type="boolean">boolean indicating whether caching is enabled.</param>
	/// </method>
	///
	setCacheEnabled:function(b){
		org.cote.js.xml.clearCache();
		org.cote.js.xml._xml_http_cache_enabled = b;
	},
	
	/// <method>
	/// <name>getCacheEnabled</name>
	/// <return-value name="b" type="boolean">boolean indicating whether caching is enabled.</return-value>
	/// </method>
	///
	getCacheEnabled:function(){
		return org.cote.js.xml._xml_http_cache_enabled;
	},
	%STOP_XML_CACHE%

	%START_XML_NAMESPACERESOLVER%
	_xml_namespace_resolver:[
		["soapenc","http://schemas.xmlsoap.org/soap/encoding/"],
		["wsdl","http://schemas.xmlsoap.org/wsdl/"],
		["soap","http://schemas.xmlsoap.org/wsdl/soap/"],
		["SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/"]
	],
	_xml_namespace_url:{},
	_xml_namespace_uri:{},
	_xml_namespace_hashed:0,
	%STOP_XML_NAMESPACERESOLVER%

	%START_XML_POOL%
	_xml_http_objects:[],
	_xml_http_object_use:0,
	_xml_http_object_count:0,
	_xml_http_object_pool_size:%XML_HTTP_POOL_SIZE%,
	_xml_http_object_pool_max:%XML_HTTP_POOL_MAXSIZE%,
	
	/* notate whether the pool was created */
	_xml_http_pool_created:0,

	/* notate whether the pool was created */
	_xml_http_pool_enabled:%XML_HTTP_POOL_ENABLED%,
/*	_xml_http_pool_enabled:(typeof DATATYPES.XMLHTTPREQUEST == DATATYPES.TYPE_FUNCTION?1:0),*/

	/* static class init - used to add in message subscriptions on demand */
	si:0,

	/// <method>
	/// <name>setPoolEnabled</name>
	/// <param name="b" type="boolean">boolean indicating whether pooling is enabled.</param>
	/// </method>
	///
	setPoolEnabled:function(b){
		org.cote.js.xml._xml_http_pool_enabled = b;
	},
	
	/// <method>
	/// <name>getPoolEnabled</name>
	/// <return-value name="b" type="boolean">boolean indicating whether pooling is enabled.</return-value>
	/// </method>
	///
	getPoolEnabled:function(){
		return org.cote.js.xml._xml_http_pool_enabled;
	},
	
	%STOP_XML_POOL%
	
	/// <method>
	/// <name>parseXmlDocument</name>
	/// <param name="s" type="String">XML source text.</param>
	/// <return-value name="oXml" type="XMLDocument">XMLDocument object.</return-value>
	/// </method>
	///
	parseXmlDocument:function(s){
		/*
			s = String of XML data
		*/
		
		var r = 0,e;
		if(!s) return 0;
		if(typeof DOMParser != DATATYPES.TYPE_UNDEFINED){
			e = new DOMParser();
			r = e.parseFromString(s,"text/xml");
		}
		else if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED){
			r = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_dom_control);
			r.async = false;
			r.loadXML(s);
		}
		else{
		    /// ...
		}
		return r;
	},
	/// <method>
	/// <name>newXmlDocument</name>
	/// <param name="s" type="String">Name of root node to create in new document.</param>
	/// <return-value name="oXml" type="XMLDocument">XMLDocument object.</return-value>
	/// </method>
	///
	newXmlDocument:function(n){
		/*
			n = required "root node" name;
		*/
		
		var r = 0,e;
		if(!n) return 0;
		if(typeof document.implementation != DATATYPES.TYPE_UNDEFINED && typeof document.implementation.createDocument != DATATYPES.TYPE_UNDEFINED){
			r = document.implementation.createDocument("",n,null);
			/* Safari bug */
			if(r != null && r.documentElement == null){
				r.appendChild(r.createElement(n));
			}
		}
		else if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED){
			r = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_dom_control);
			e = r.createElement(n);
			r.appendChild(e);
		}
		else{
		    /// ...
		}
		return r;
	},
	
	/// <method>
	/// <name>clear</name>
	/// <description>Clears the request maps and caches.</description>
	/// </method>
	///
	clear:function(){
		var _x = org.cote.js.xml;

		%START_XML_CACHE%
		_x.clearCache();
		%STOP_XML_CACHE%
		
		%START_XML_POOL%
		_x.resetXmlHttpObjectPool();
		%STOP_XML_POOL%
		
		_x._xml_requests = [];
		_xml_requests_map = [];
		
		return 1;

	},

	%START_XML_CACHE%
	/*
		2005/09/09 - better clear out the cached ids and arrays as well as nullifying the object pointers
	*/
	/// <method>
	/// <name>clearCache</name>
	/// <description>Clears the response cache.</description>
	/// </method>
	///
	clearCache:function(){
		var _x = org.cote.js.xml,i = 0,o;
		for(;i<_x._xml_requests.length;i++){
			o = _x._xml_requests[i];
			if(o.c && typeof o.cd == DATATYPES.TYPE_OBJECT){
				%START_DEBUG_MESSAGE%
				org.cote.js.message.MessageService.sendMessage("Clear cached DOM for " + o.i,"200.1");
				%STOP_DEBUG_MESSAGE%				
				o.cd = 0;
			}
			o.obj = null;
			o.ih = null;
			o.h = null;
		}
		_x._xml_requests = [];
		_x._xml_requests_map = [];
	},

	%STOP_XML_CACHE%
	%START_XML_POOL%
	
	/// <method>
	/// <name>getXmlHttpArray</name>
	/// <return-value name="aXml" type="array">Array of XmlHttp objects.</return-value>
	/// </method>
	///
	getXmlHttpArray:function(){
		return org.cote.js.xml._xml_http_objects;
	},
	
	/// <method>
	/// <name>resetXmlHttpObjectPool</name>
	/// <description>Resets the current pool with new instances of XMLHttpRequest objects.</description>
	/// </method>
	///
	resetXmlHttpObjectPool:function(){
		var _x = org.cote.js.xml,i = 0,o;
		_x._xml_http_pool_created = 1;
		_x._xml_http_object_use=0;
		_x._xml_http_objects=[];
		_x._xml_http_object_count = _x._xml_http_object_pool_size;
		for(;i < _x._xml_http_object_pool_size; i++)
			o = _x._xml_http_objects[i] = _x.newXmlHttpObject(1,i);
		
	},
	%STOP_XML_POOL%
	
	/// <method>
	/// <name>testXmlHttpObject</name>
	/// <description>Tests whether an XMLHTTPRequest object can be created.</description>
	/// <return-value name="b" type="boolean">Bit indicating whether a new XMLHTTPRequest object was created.</return-value>
	/// </method>
	///
	testXmlHttpObject:function(){
		return org.cote.js.xml.newXmlHttpObject(null,%START_XML_POOL%null,%STOP_XML_POOL%1);
	},
	
	/// <method private = "1">
	/// <name>newXmlHttpObject</name>
	/// <description>Creates a new XMLHTTPRequest object.</description>
	/// <param name="b" type="boolean">Bit indicating whether to wrap the new object in an internal XmlHttp object for use with pooling.</param>
	/// <param name="i" type="int">Pool index to set on new XmlHttp object.</param>
	/// <param name="z" type="boolean">Bit indicating whether this is a test operation, and to return true if the object was created, or false otherwise.</param>
	/// <return-value name="v" type="variant">Return value is determined by the specified parameters.</return-value>
	/// </method>
	///
	newXmlHttpObject:function(b,%START_XML_POOL%i,%STOP_XML_POOL%z){
		/*
			b = return a hash for use with pooling
			i = pool index value.  b must be true for i to be used
			z = used for testing object creation
		*/
		var o = null,v,f,_m = org.cote.js.message.MessageService;
		if(typeof DATATYPES.XMLHTTPREQUEST != DATATYPES.TYPE_UNDEFINED){	
			o = new DATATYPES.XMLHTTPREQUEST();
			if(z) return 1;
		}
		else if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED){
			%START_CATCH_ERROR%
			try{
			%STOP_CATCH_ERROR%
				o = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_http_control);
				if(z) return 1;
			%START_CATCH_ERROR%
			}
			catch(e){
				_m.sendMessage("XMLError: " + (e.description?e.description:e.message),"512.4",(z?1:0));
			}
			%STOP_CATCH_ERROR%
			if(z) return 0;
		}
		%START_XML_POOL%
		if(b && typeof i == DATATYPES.TYPE_NUMBER){
			v= {
				o:o,
				u:0,
/*				use_count:0,*/
				i:i,
				/* vid = variant id */
				v:-1,
				h:0
			};

			return v;
		}
		else{
	%STOP_XML_POOL%
			return o;
	%START_XML_POOL%
		}
	%STOP_XML_POOL%
	},
	%START_XML_POOL%
	
	/// <method private = "1">
	/// <name>returnXmlHttpObjectToPool</name>
	/// <description>Returns an in-use XmlHttp object to the pool of available resources.</description>
	/// <param name="i" type="int">Pool index of the XmlHttp object to be returned.</param>
	/// <param name="y" type="boolean">Bit indicating whether the pool object was requested for asynchronous operation.</param>
	/// </method>
	///
	returnXmlHttpObjectToPool:function(i,y){
		var _x = org.cote.js.xml,b=0,o,a;
		a = _x._xml_http_objects;

		if(typeof a[i] == DATATYPES.TYPE_OBJECT){
			o = a[i];
			if(o.i >= _x._xml_http_object_pool_size)

				%START_DEBUG_MESSAGE%
				{
				org.cote.js.message.MessageService.sendMessage("Destroy returned pool object #(" + o.i + ")","200.1");
				%STOP_DEBUG_MESSAGE%
				
				a[i] = 0;
			%START_DEBUG_MESSAGE%
			}
			%STOP_DEBUG_MESSAGE%

			%START_DEBUG_MESSAGE%
			org.cote.js.message.MessageService.sendMessage("Drop handlers for pool object #(" + o.i + ")","200.1");
			%STOP_DEBUG_MESSAGE%

			%START_CATCH_ERROR%
			try{
			%STOP_CATCH_ERROR%
				if(!y){
					/* 2005/09/07 Fix for Opera 8 */
					/*
						Why bother checking the instance of?
						Either XMLHttpRequest is here and use it, or it's not so don't use it
					*/
					/*if(typeof XMLHttpRequest == "function" || (typeof XMLHttpRequest == "object" &&  o.xml_object instanceof XMLHttpRequest))*/
					/* 2005/09/08 Fix for Safari */
					if(typeof DATATYPES.XMLHTTPREQUEST != DATATYPES.TYPE_UNDEFINED){
						if(typeof o.o.removeEventListener == DATATYPES.TYPE_FUNCTION)
							o.o.removeEventListener("load",o.h,false);
						else
							o.o.onreadystatechange = _x._stub;
					}
					else if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED &&  o.o instanceof DATATYPES.ACTIVEXOBJECT)
						o.o.onreadystatechange=_x._stub;
					
					o.h = 0;
				}
			%START_CATCH_ERROR%
			}
			catch(e){
				org.cote.js.message.MessageService.sendMessage("Error in returnXmlHttpObjectToPool: " + (e.description?e.description:e.message),"512.4",1);
			}		
			%STOP_CATCH_ERROR%
			o.o.abort();
			o.u = 0;
			o.v = -1;


/*
				if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED && o.o instanceof DATATYPES.ACTIVEXOBJECT)
					o.o.onreadystatechange = o.h;
*/				
			_x._xml_http_object_use--;
		}
		%START_DEBUG_MESSAGE%
		else{
			org.cote.js.message.MessageService.sendMessage("Invalid pool id '" + i + "'","200.4");
		}
		%STOP_DEBUG_MESSAGE%
		return 1;
	},
	
	/// <method private = "1">
	/// <name>getXmlHttpObjectFromPool</name>
	/// <description>Retrieves the next available XmlHttp object from the pool of available resources.</description>
	/// <param name="y" type="boolean">Bit indicating whether the pool object is requested for asynchronous operation.</param>
	/// <return-value name="oXml" type="XmlHttp">An XmlHttp object.</return-value>
	/// </method>
	///	
	getXmlHttpObjectFromPool:function(y){
		var _x = org.cote.js.xml,i = 0,b=0,o,a,_m=org.cote.js.message.MessageService,n=-1,z = 0;

		if(!_x._xml_http_pool_created) _x.resetXmlHttpObjectPool();
		a = _x._xml_http_objects;
		for(;i<a.length;i++){
			if(typeof a[i] == DATATYPES.TYPE_OBJECT && typeof a[i].u == DATATYPES.TYPE_NUMBER && !a[i].u){
				a[i].u = 1;
				b = i;
				/* yes, we indeed got a good mark */
				z = 1;
				break;
			}
			/* mark the next known null marker for re-use*/
			if(n == -1 && !a[i])
				n = i;
			
		}

		if(!z){
			b = (n > -1)?n:a.length;
			if(b < _x._xml_http_object_pool_max){
				a[b] = _x.newXmlHttpObject(1,b);
				a[b].u = 1;
				%START_DEBUG_MESSAGE%
				_m.sendMessage("Allocate additional objects to pool (" + b + ")","200.1");
				%STOP_DEBUG_MESSAGE%
			}
			else{
				_m.sendMessage("Max pool size reached!","200.4");
				return null;
			}
		}

		if(b > -1){
			_x._xml_http_object_use++;
			o = a[b];
			%START_CATCH_ERROR%
			try{
			%STOP_CATCH_ERROR%
				if(!y){

					/* 2005/09/07 Fix for Opera 8 */
					/*
						Why bother checking the instance of?
						Either XMLHttpRequest is here and use it, or it's not so don't use it
					*/
					
					/*if(typeof XMLHttpRequest == "function" || (typeof XMLHttpRequest == "object" &&  o.xml_object instanceof XMLHttpRequest)){*/
					/* 2005/09/08 Fix for Safari */
					if(typeof DATATYPES.XMLHTTPREQUEST != DATATYPES.TYPE_UNDEFINED){
						if(typeof o.o.addEventListener == DATATYPES.TYPE_FUNCTION){
							o.h = function(){org.cote.js.xml._handle_xml_request_load(b);};
							o.o.addEventListener("load",o.h,false);
						}
						else{
							o.h = function(){org.cote.js.xml._handle_xml_request_readystatechange(b);};
							o.o.onreadystatechange = o.h;
						}
					}
					else if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED &&  o.o instanceof DATATYPES.ACTIVEXOBJECT){
						o.h = function(){org.cote.js.xml._handle_xml_request_readystatechange(b);};
						/*
							Can't attach an event to this object with attachEvent
						*/
						o.o.onreadystatechange=o.h;
					}
				}
			%START_CATCH_ERROR%
			}
			catch(e){
				_m.sendMessage("Error in getXmlHttpObjectFromPool: " + (e.description?e.description:e.message),"512.4",1);
			}		
			%STOP_CATCH_ERROR%
			
			return o;
		}
		
		return null;

	},
	%STOP_XML_POOL%
	
	_handle_xml_request_load:function(i){
		/*
			i = xml id
		*/
		var _x=org.cote.js.xml,o,v,_m=org.cote.js.message.MessageService,z;
		%START_CATCH_ERROR%
		try{
		%STOP_CATCH_ERROR%
		%START_XML_POOL%
			if(_x._xml_http_pool_enabled && typeof _x._xml_http_objects[i] == DATATYPES.TYPE_OBJECT){
				z = _x._xml_http_objects[i].v;
				if(z == -1){
					_m.sendMessage("Invalid pool index for " + i,"200.4",1);
					return 0;
				}
				i = z;
			}
		%STOP_XML_POOL%
		    
			if(typeof _x._xml_requests_map[i] == DATATYPES.TYPE_NUMBER){
				o = _x._xml_requests[_x._xml_requests_map[i]];
				v = {text:null, xdom:null, json:null, id:(o.bi?o.bi:i)};
				
				%START_SUPPORT_LOCALFILESYSTEM%
				if(
					o.u.match(/^file:/i)
					&&
					typeof DATATYPES.ACTIVEXOBJECT == "function"
					&&
					o.o instanceof DATATYPES.ACTIVEXOBJECT
				){
					var mp = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_dom_control);
					mp.loadXML(o.o.responseText);
					v.xdom = mp;
				} else %STOP_SUPPORT_LOCALFILESYSTEM% if(o.o != null){
					/* && (o.t || o.o.responseXML != null)){*/
					if(o.t){
						v.text = o.o.responseText;
						if(o.t == 2 && typeof JSON != DATATYPES.TYPE_UNDEFINED){
							try{
								v.json = JSON.parse(v.text,_x.JSONReviver);
							}
							catch(e){
								v.json = null;
								v.error = e.message;
							}
						}
					}
					else{
						v.xdom = o.o.responseXML;
						if(o.o.responseXML == null || o.o.responseXML.documentElement == null && o.o.responseText != null){
							v.xdom = _x.parseXmlDocument(o.o.responseText);
							v.text = o.o.responseText;
						}
					}
				}
				if(!o.t && (v.xdom == null || v.xdom.documentElement.nodeName == "parsererror")){
					_m.sendMessage("Error loading '" + o.u + "'. Response text is: " + o.o.responseText + ".   Async is " + o.a + "; Pool Index is " + o.pi,"540.4",1);
				}
				else if(o.t == 2 && v.json == null){
					_m.sendMessage("Error loading '" + o.u + "'. The internal JSON object reference is null.  Async is " + o.a + "; Pool Index is " + o.pi,"540.4",1);
				}
				/*
				else if(o.o != null)
					_m.sendMessage("Error loading '" + o.u + "'. Response text is: " + o.o.responseText,"540.4",1);
				
				else
					_m.sendMessage("Error loading '" + o.u + "'. The internal XML object reference is null.  Async is " + o.a%START_XML_POOL% + "; Pool Index is " + o.pi%STOP_XML_POOL%,"540.4",1);
				*/
	
				o.r = 1;
			
				if(o.ih){
/*				
					if(typeof DATATYPES.XMLHTTPREQUEST == DATATYPES.TYPE_FUNCTION && o.obj instanceof DATATYPES.XMLHTTPREQUEST){
						o.obj.removeEventListener("load",o.ih,false);
					}
					else if(typeof DATATYPES.ACTIVEXOBJECT == DATATYPES.TYPE_FUNCTION &&  o.obj instanceof DATATYPES.ACTIVEXOBJECT){
						o.obj.onreadystatechange=0;
					}
*/
					o.ih = 0;
				}
				
				%START_XML_CACHE%
				if(_x._xml_http_cache_enabled && o.c){
					o.cd = v.xdom;
				}
				%STOP_XML_CACHE%
				
				org.cote.js.message.MessageService.publish("onloadxml",v);
				if(typeof o.h==DATATYPES.TYPE_FUNCTION) o.h("onloadxml",v);
	
				/*
					clear out the request object
				*/
				%START_XML_POOL%
				if(o.pi > -1)
					_x.returnXmlHttpObjectToPool(o.pi,!o.a);
				
				%STOP_XML_POOL%
				o.o = 0;
	
			}
			else{
				_m.sendMessage("Invalid id reference: " + i,"200.4",1);
			}
		%START_CATCH_ERROR%
		}
		catch(e){
			_m.sendMessage("Error in handle_xml_request_load: " + (e.description?e.description:e.message),"512.4",1);
		}
		%STOP_CATCH_ERROR%
	},

	_handle_xml_request_readystatechange:function(i){
		var _x=org.cote.js.xml,o;

		/*
			Slightly different behavior for pooled requests and non-pooled requests.
			
			Ultimately, the issue IE won't detach the onreadystate event handler, so the index into the pool is passed
			instead of the unique request id.  This should actually be better anyway as it removes the need to constantly 
			attach and detach event handlers on the pooled objects.
		*/
		%START_XML_POOL%
		if(_x._xml_http_pool_enabled && typeof _x._xml_http_objects[i] == DATATYPES.TYPE_OBJECT){
			o = _x._xml_http_objects[i];
			if(o != null && typeof o.o == DATATYPES.TYPE_OBJECT && o.o.readyState == 4){
				_x._handle_xml_request_load(i);
			}
		}
		else %STOP_XML_POOL% if(typeof _x._xml_requests_map[i] == DATATYPES.TYPE_NUMBER){
			o = _x._xml_requests[_x._xml_requests_map[i]];
			if(typeof o.o == DATATYPES.TYPE_OBJECT && o.o.readyState == 4){

				_x._handle_xml_request_load(i);
			}
		}
	},
	
	/// <method>
	/// <name>getJSON</name>
	/// <description>Retrieve a JSON object from the specified path.</description>
	/// <param name="p" type="String">Path of the JSON source.  If specifying the server, note the server name and port must match the context host name and port.</param>
	/// <param name="h" type="function" optional = "1" default="null">Function to invoke when a response is received.</param>
	/// <param name="a" type="boolean" optional = "1" default="false">Bit indicating whether the request is an asynchronous operation.</param>
	/// <param name="i" type="String" optional = "1" default="null">Identifier to assign to the request.</param>
	/// <param name="c" type="boolean" optional = "1" default="false">Bit indicating whether the response should be cached.</param>
	/// <return-value name="v" type="variant">Returns boolean for asynchronous operations, and a JSON object for synchronous operations.</return-value>
	/// </method>
	///	
	getJSON:function(p,h,a,i,c){
	/*
			p = path
			h = handler
			a = async
			i = id
			c = cached
	*/
		return org.cote.js.xml._request_xmlhttp(p,h,a,i,0,null,c,2);
	},
	/// <method>
	/// <name>getText</name>
	/// <description>Retrieve text from the specified path.</description>
	/// <param name="p" type="String">Path of the text source.  If specifying the server, note the server name and port must match the context host name and port.</param>
	/// <param name="h" type="function" optional = "1" default="null">Function to invoke when a response is received.</param>
	/// <param name="a" type="boolean" optional = "1" default="false">Bit indicating whether the request is an asynchronous operation.</param>
	/// <param name="i" type="String" optional = "1" default="null">Identifier to assign to the request.</param>
	/// <param name="c" type="boolean" optional = "1" default="false">Bit indicating whether the response should be cached.</param>
	/// <return-value name="v" type="variant">Returns boolean for asynchronous operations, and text for synchronous operations.</return-value>
	/// </method>
	///	
	getText:function(p,h,a,i,c){
	/*
			p = path
			h = handler
			a = async
			i = id
			c = cached
	*/
		return org.cote.js.xml._request_xmlhttp(p,h,a,i,0,null,c,1);
	},
	/*
		getXml(path,handler,async,id,caching);
		
		id is optional.  Use this where two or more xml transactions will be directed
		through the same handler.
		
	*/
	
	/// <method>
	/// <name>getXml</name>
	/// <description>Retrieve an XML document from the specified path.</description>
	/// <param name="p" type="String">Path of the XML source.  If specifying the server, note the server name and port must match the context host name and port.</param>
	/// <param name="h" type="function" optional = "1" default="null">Function to invoke when a response is received.</param>
	/// <param name="a" type="boolean" optional = "1" default="false">Bit indicating whether the request is an asynchronous operation.</param>
	/// <param name="i" type="String" optional = "1" default="null">Identifier to assign to the request.</param>
	/// <param name="c" type="boolean" optional = "1" default="false">Bit indicating whether the response should be cached.</param>
	/// <return-value name="v" type="variant">Returns boolean for asynchronous operations, and an XMLDocument object for synchronous operations.</return-value>
	/// </method>
	///	
	getXml:function(p,h,a,i%START_XML_CACHE%,c%STOP_XML_CACHE%){
	/*
			p = path
			h = handler
			a = async
			i = id
			c = cached
	*/
		return org.cote.js.xml._request_xmlhttp(p,h,a,i,0,null%START_XML_CACHE%,c%STOP_XML_CACHE%);
	},
	
	/// <method>
	/// <name>postJSON</name>
	/// <description>Posts a JSON object to the specified path and returns any JSON response.</description>
	/// <param name="p" type="String">Path of the XML source.  If specifying the server, note the server name and port must match the context host name and port.</param>
	/// <param name="d" type="XMLDocument">XMLDocument to post the server</param>
	/// <param name="h" type="function" optional = "1" default="null">Function to invoke when a response is received.</param>
	/// <param name="a" type="boolean" optional = "1" default="false">Bit indicating whether the request is an asynchronous operation.</param>
	/// <param name="i" type="String" optional = "1" default="null">Identifier to assign to the request.</param>
	/// <return-value name="v" type="variant">Returns boolean for asynchronous operations, and a JSON object for synchronous operations.</return-value>
	/// </method>
	///	
	postJSON:function(p,d,h,a,i){
		/*
			Caching is not provided for the postXml wrapper.
		*/
		if(typeof JSON == "undefined"){
			alert("Missing JSON interpreter");
			return 0;
		}
		return org.cote.js.xml._request_xmlhttp(p,h,a,i,1,JSON.stringify(d),0,2);
	},
	/// <method>
	/// <name>postText</name>
	/// <description>Posts text to the specified path and returns any text response.</description>
	/// <param name="p" type="String">Path of the XML source.  If specifying the server, note the server name and port must match the context host name and port.</param>
	/// <param name="d" type="XMLDocument">XMLDocument to post the server</param>
	/// <param name="h" type="function" optional = "1" default="null">Function to invoke when a response is received.</param>
	/// <param name="a" type="boolean" optional = "1" default="false">Bit indicating whether the request is an asynchronous operation.</param>
	/// <param name="i" type="String" optional = "1" default="null">Identifier to assign to the request.</param>
	/// <return-value name="v" type="variant">Returns boolean for asynchronous operations, and text for synchronous operations.</return-value>
	/// </method>
	///	
	postText:function(p,d,h,a,i){
		/*
			Caching is not provided for the postXml wrapper.
		*/
		return org.cote.js.xml._request_xmlhttp(p,h,a,i,1,d,0,1);
	},
	
	/// <method>
	/// <name>postXml</name>
	/// <description>Posts an XML document to the specified path and returns any XML response.</description>
	/// <param name="p" type="String">Path of the XML source.  If specifying the server, note the server name and port must match the context host name and port.</param>
	/// <param name="d" type="XMLDocument">XMLDocument to post the server</param>
	/// <param name="h" type="function" optional = "1" default="null">Function to invoke when a response is received.</param>
	/// <param name="a" type="boolean" optional = "1" default="false">Bit indicating whether the request is an asynchronous operation.</param>
	/// <param name="i" type="String" optional = "1" default="null">Identifier to assign to the request.</param>
	/// <return-value name="v" type="variant">Returns boolean for asynchronous operations, and an XMLDocument object for synchronous operations.</return-value>
	/// </method>
	///	
	postXml:function(p,d,h,a,i){
		/*
			Caching is not provided for the postXml wrapper.
		*/
		return org.cote.js.xml._request_xmlhttp(p,h,a,i,1,d,0);
	},
	/*
		_request_xml is asynchronous.
	*/
	
	/// <method private = "1">
	/// <name>_request_xmlhttp</name>
	/// <description>Assembles and opens an XMLHTTP Request.</description>
	/// <param name="p" type="String">Path to the XML data source.</param>
	/// <param name="h" type="function" optional="1" default="null">Handler invoked for asynchronous requests.</param>
	/// <param name="a" type="boolean" optional="1" default = "false">Bit indicating whether the request is asynchronous.</param>
	/// <param name="i" type="String" optional = "1" default = "auto">Identifier used to track the request and retrieve cached results.</param>
	/// <param name="x" type="boolean" optional="1" default = "false">Bit indicating whether the request is a post.</param>
	/// <param name="d" type="XMLDocument" optional="1" default = "null">XML Document to send with post request.</param>
	/// <param name="c" type="boolean" optional="1" default = "false">Bit indicating whether the response should be cached.</param>
	/// <param name="t" type="int" optional="1" default = "0">Int indicating whether the request and response as text (1) or JSON (2) instead of XML (0).</param>
	/// <return-value name="v" type="variant">Returns a boolean value for asynchronous requests, and an XML Document for synchronous requests.</return-value>
	/// </method>
	///	

	_request_xmlhttp:function(p,h,a,i,x,d%START_XML_CACHE%,c%STOP_XML_CACHE%,t){
		/*
			p = path
			h = handler
			a = async
			i = id
			x = is_post as bool
			d = data as string or DomDocument
			
			r = pool/new x obj
			b = bool
			
			c = cache result
			
			t = treat response only as text.  1 == text, 2 == json

		*/
		
		var _x=org.cote.js.xml,f,o=null,v,_m=org.cote.js.message.MessageService,y,z,r,b,b_ia,g,bi=0;
		
		if(!_x.si) _x.StaticInitialize();

		if(typeof p != DATATYPES.TYPE_STRING || p.length == 0){
			_m.sendMessage("Invalid path parameter in _request_xmlhttp","512.4",1);
			return 0;
		}
		
		if(typeof c==DATATYPES.TYPE_UNDEFINED) c = 0;
		if(typeof x==DATATYPES.TYPE_UNDEFINED) x = 0;
		if(typeof d==DATATYPES.TYPE_UNDEFINED) d = null;

		z = (x?"POST":"GET");
		if(typeof i!=DATATYPES.TYPE_STRING) i=org.cote.js._get_gunid();

		/* check for a cached instance */
		if(
			_x._xml_http_cache_enabled
			&&
			typeof _x._xml_requests_map[i] == DATATYPES.TYPE_NUMBER
			&&
			( r = _x._xml_requests[_x._xml_requests_map[i]] )
		){
			%START_XML_CACHE%
			if(r.c && (typeof r.cd == DATATYPES.TYPE_OBJECT || typeof r.ct == DATATYPES.TYPE_STRING)){
				if(!t)
					b = {xdom:r.cd, id:i};
				else{
					b = {text:r.ct, id:i};
					if(t == 2 && typeof JSON != DATATYPES.TYPE_UNDEFINED)
						b.json = JSON.parse(r.ct,_x.JSONReviver);	
					
				}
				if(b){
					_m.publish("onloadxml",b);
					if(typeof h == DATATYPES.TYPE_FUNCTION) h("onloadxml",b);

					%START_DEBUG_MESSAGE%
					_m.sendMessage("Return cached copy","200.1");
					%STOP_DEBUG_MESSAGE%

					return r.cd;
				}
			}
			%STOP_XML_CACHE%
			%START_XML_CACHE_RACE_CHECK%
			/*
				Race condition for an XML document with a specific id,
				that hasn't finished loading
				
				If there is a request, and that request isn't complete,
				then cook up a backup-request id and disable caching
			*/
			/*
				06/17/2003
					Removed '!r.a && ' check for sync only requests
					Removed 'r.c' check for caching
			*/
			%START_XML_CACHE% else %STOP_XML_CACHE% if(!r.r){
				/* force disable caching for this request */
				c = 0;
				/* backup the id */
				bi = i;
				/* create a random id */
				i = org.cote.js._get_gunid();
				%START_DEBUG_MESSAGE%
				_m.sendMessage("Handle race condition for XML Id '" + bi + "'","200.4");
				%STOP_DEBUG_MESSAGE%
			}
			%STOP_XML_CACHE_RACE_CHECK%
		}

		
		/* get a new XML object, or a pooled object depending on the settings */
		%START_XML_POOL%
		b = _x._xml_http_pool_enabled;
		if(_x.gadget_mode){
			a = 0;
			b = 0;
			p = _x.gadget_base_path + p;
			r = new ActiveXObject(_x.gadget_xml_control);
		}
		else if(b){
			%START_DEBUG_MESSAGE%
			{
			%STOP_DEBUG_MESSAGE%
			r = _x.getXmlHttpObjectFromPool(!a);
			%START_DEBUG_MESSAGE%
			if(r) _m.sendMessage("Request pooled object #" + r.i,"200.1");
			}
			%STOP_DEBUG_MESSAGE%
		}
		else{
		%STOP_XML_POOL%
			r = _x.newXmlHttpObject();
		%START_XML_POOL%
		}
		%STOP_XML_POOL%
		/*
			Unable to obtain an XML object, so bail out.
		*/
		if(!%START_XML_POOL%(b?(r&&r.o):%STOP_XML_POOL%r%START_XML_POOL%)%STOP_XML_POOL%){
			_m.sendMessage("Null XML object in in _request_xmlhttp.","512.4");

			/* 2005/09/09 - raise the handler for async requests */
			b = {text:null, xdom:null, error:"Null XML object in _request_xmlhttp", id:i};
			if(typeof h == DATATYPES.TYPE_FUNCTION) h("onloadxml",b);

			return 0;
		}

		/* update the pool id reference, if pooling is enabled */
		%START_XML_POOL%
		if(b) r.v = i;
		%STOP_XML_POOL%
		
		/// Create a new internal object representing the xml request 
		///
		y = _x._xml_requests.length;

		_x._xml_requests[y] = {
			u:p,
			i:i,
			bi:bi,
			a:a,
			o:%START_XML_POOL%(b?r.o:%STOP_XML_POOL%r%START_XML_POOL%)%STOP_XML_POOL%,
			ih:0,
			h:h,
/*			method:(x?1:0),*/

			%START_XML_POOL%
			pi:(b?r.i:-1),
			%STOP_XML_POOL%

			%START_XML_CACHE%
			c:c,
			cd:0,
			%STOP_XML_CACHE%
			/// Response status
			r:0,
			/// Text type
			t:t
		};
		
		/// Map the object to the id
		///
		_x._xml_requests_map[i]=y;
		o = _x._xml_requests[y].o;

		/// Massage the path reference
		///
		if(!p.match(/:\/\//)){
			var m,e=new RegExp("^/");
			if(!p.match(e)){
				if(_x.base_path){
					p = _x.base_path + p;
				}
				else{
					m=location.pathname;
					if(m.match(/\\/)) m = m.replace(/\\/g,"/");
					m=m.substring(0,m.lastIndexOf("/")+1);
					p=m + p;
				}
			}

			if(!location.protocol.match(/^file:$/i))
				p=location.protocol + "//" + location.host + p;
			
			else
				p = location.protocol + "//" + p;
		}

/*
		if(!p.match(/:\/\//)){
			var m,e=new RegExp("^/");
			if(!p.match(e)){
				m=location.pathname;
				m=m.substring(0,m.lastIndexOf("/")+1);
				p=m + p;
			}
			p=location.protocol + "//" + location.host + p;
		}
*/
		_x._xml_requests[y].u = p;

		/*
			Add event handlers based on instance of XML object
			
			Must check for typeof object before instanceof or IE will bomb out.
			
			Check for:
				a) this is not a pooled request; pooled requests use index->id maps
				b) this as an async request
				c) the type of request object
		*/
		b_ia = (typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED &&  o instanceof DATATYPES.ACTIVEXOBJECT)?1:0;
		
		/// 2008/04/24
		/// Fix for IE 7 file system support
		/// The native XMLHttpRequest support is reported as an ActiveX instance
		/// Treat this filesystem request as a cache request
		/// Include a check to allow IE 6 through, since it works just fine
		///
		%START_SUPPORT_LOCALFILESYSTEM%
		if(b_ia && typeof XMLHttpRequest != DATATYPES.TYPE_UNDEFINED && p.match(/^file/i)){
		        _x.returnXmlHttpObjectToPool(_x._xml_requests[y].pi,!a);
		        o = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_dom_control);
		        /// Restore any backup id
		        ///
		        if(bi) i = bi;
				o.load(p);
				b = {xdom:o,id:i};
				_m.publish("onloadxml",b);
				if(typeof h == DATATYPES.TYPE_FUNCTION) h("onloadxml",b);

				%START_DEBUG_MESSAGE%
				_m.sendMessage("IE 7 XMLHttpRequest via Filesystem","200.1");
				%STOP_DEBUG_MESSAGE%

				return o;
		}
		%STOP_SUPPORT_LOCALFILESYSTEM%
		%START_CATCH_ERROR%
		try{
		%STOP_CATCH_ERROR%
			/*
				05/30/2003
				Remove check for async only because non-pooled async requests should also go through the load listener.
			*/
			/*if(%START_XML_POOL%!b && %STOP_XML_POOL%typeof DATATYPES.XMLHTTPREQUEST != DATATYPES.TYPE_UNDEFINED && o instanceof DATATYPES.XMLHTTPREQUEST){*/
			/*if(!b && a && (typeof XMLHttpRequest == "function" || (typeof XMLHttpRequest == "object" && o instanceof XMLHttpRequest))){*/

			if(%START_XML_POOL%!b && %STOP_XML_POOL% a && typeof DATATYPES.XMLHTTPREQUEST != DATATYPES.TYPE_UNDEFINED){
				if(typeof o.addEventListener == DATATYPES.TYPE_FUNCTION){
					_x._xml_requests[y].ih = function(){org.cote.js.xml._handle_xml_request_load(i);};
					o.addEventListener("load",_x._xml_requests[y].ih,false);
				}
				else{
					_x._xml_requests[y].ih = function(){org.cote.js.xml._handle_xml_request_readystatechange(i);};
					o.onreadystatechange=_x._xml_requests[y].ih;
				}
			}

			else if(%START_XML_POOL%!b && %STOP_XML_POOL%a && b_ia){
				_x._xml_requests[y].ih = function(){org.cote.js.xml._handle_xml_request_readystatechange(i);};
				/*
					Can't attach an event to this object with attachEvent
				*/
				o.onreadystatechange=_x._xml_requests[y].ih;
			}
		%START_CATCH_ERROR%
		}
		catch(e){
			_m.sendMessage("Error in _request_xmlhttp: " + (e.description?e.description:e.message),"512.4",1);
		}		
		%STOP_CATCH_ERROR%
		
		/*
			There is a problem with the DATATYPES.ACTIVEXOBJECT not liking the multiple levels of object references,
			particularly the embedded array reference into the http_objects array used for pooling.
			The good news is this only seems to apply to syncronous requests, and only for DATATYPES.ACTIVEXOBJECTs.
			The bad news is fixing the problem requires the following:
				- change the onreadystatechange handler to point elsewhere.  Since this can't be null, its pointed at an empty stub function.
				- set the array reference for http_objects to null.
			At this point, those referencers are:
		*/
		%START_XML_POOL%
		if(b && !a){
/*			if(b_ia) o.onreadystatechange = _x._stub;*/
			_x._xml_http_objects[_x._xml_requests[y].pi] = 0;
		}
		%STOP_XML_POOL%
		
		g = (a?true:false);
		o.open(z,p,g);

		/// If supported, include the outgoing content type
		///
		if (typeof o.setRequestHeader != DATATYPES.TYPE_UNDEFINED) {
			/// Reuse z
			z = (t ? _x.text_content_type : _x.xml_content_type );
			if(_x.auto_content_type && !t && typeof d == DATATYPES.TYPE_STRING) z = org.cote.js.xml.form_content_type;
			o.setRequestHeader("Content-Type", z);

		}
		o.send(d);
		if(!a){
			/*
				Don't use the reference in the requests array here because it loses context when he open and send methods are invoked.
				Instead, since this is synchronous, just use 'o'
				
				This is symptomatic of the IE problem mentioned above, but the root cause seems to be
				the manner in which the DATATYPES.ACTIVEXOBJECT is stored in the array.
				
				The issue manifests as querying responseXML throws an error, or undefined and the object references get out of sync.
				This can be tested by comparing o == _x._xml_requests[y].obj
				
				With the IE fix in place, the test is true.
				Mozilla is false, but that isn't an issue (right now) because the response can still be obtained.
			*/

			z = (t ? o.responseText : o.responseXML);

			%START_SUPPORT_LOCALFILESYSTEM%
			if(
				!t
				&&
				p.match(/^file:/i)
				&&
				b_ia
			){
				var mp = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_dom_control);
				mp.loadXML(o.responseText);
				z = mp;

			} 
			else %STOP_SUPPORT_LOCALFILESYSTEM% if(o.responseXML == null || o.responseXML.documentElement == null){
				z = _x.parseXmlDocument(o.responseText);
			}
			
			/*
				Now that the request has been made, time for part 2 of the IE Synchronous problem.
				Reset the pool object (where the o property contains the XMLHTTPRequest object) to the array.
				Also, manually invoke the _handle_xml_request_load method
			*/
			%START_XML_POOL%
			if(b){
				/*&& b_ia*/
				_x._xml_http_objects[_x._xml_requests[y].pi] = r;
				_x._handle_xml_request_load(_x._xml_requests[y].pi);
			}
			else{
			%STOP_XML_POOL%
				 _x._handle_xml_request_load(i);
							
			%START_XML_POOL%
			}			
			%STOP_XML_POOL%
			
			_x._xml_requests[y].o = null;
			
			if(%START_XML_POOL%!b && %STOP_XML_POOL%_x._xml_requests[y].pi > -1)
				_x.returnXmlHttpObjectToPool(_x._xml_requests[y].pi,!a);
			
			
			return z;
		}
		return 1;
	},

	%START_XML_TRANSFORM%
	
	/// <method>
	/// <name>transformNode</name>
	/// <description>Transforms the specified Document with the specified XSL document.</description>
	/// <param name="x" type="variant">XML Document to be transformed.  If specified as a string, the string is used as a path to request the XML Document.</param>
	/// <param name="s" type="Document">XSL Document to transform the XML Document.  If specified as a string, the string is used as a path to request the XSL Document.</param>
	/// <param name="n" type="DOMNode" optional="1" default = "null">DOMNode to transform.</param>
	/// <param name="i" type="String" optional="1" default = "null">Identifier used when requesting the XML Document.</param>
	/// <param name="j" type="String" optional="1" default = "null">Identifier used when requesting the XSL Document.</param>
	/// <param name="p" type="boolean" optional = "1" default = "false">Bit indicating whether a request for the XSL Document should be cached.</param>
	/// <param name="t" type="boolean" optional = "1" default = "false">Bit indicating whether the transformation should expect a type text/plain as a result.</param>
	/// <return-value name="v" type="variant">Depending on the type of copy operation, returns a reference to the newly created node.</return-value>
	/// </method>
	///
	transformNode:function(x, s, n, i, j, p, t){
		/*
			x = xml document
			s = xsl document
			n = optional node reference
			i = optional id for requesting XML
			j = optional id for requesting XSL
			p = optional cache bit for requesting XSL
		*/

		var xp, o = null,_m = org.cote.js.message.MessageService,_x = org.cote.js.xml,v,a,b,c,d;

		if(typeof x == DATATYPES.TYPE_STRING && x.length > 0){
			if(p && !i) p =0;
			v = x;
			x = _x.getXml(x,0,0,i,p);

			if(v.match(/\?(\S*)$/)){
				v = v.match(/\?(\S*)/)[1];
				a = v.split("&");
				for(b=0;b<a.length;b++){
					c = a[b].split("=");
					x.documentElement.setAttribute(c[0],c[1]);
				}
			}
		}

		if(typeof s == DATATYPES.TYPE_STRING && s.length > 0){
			if(p && !j) p =0;
			s = _x.getXml(s,0,0,j,p);
		}
		
		if(typeof x != DATATYPES.TYPE_OBJECT || x == null || typeof s != DATATYPES.TYPE_OBJECT || s == null){
			_m.sendMessage("Invalid parameters in transformNode. Xml Node = " + x + ", xsl document = " + s,"512.4",1);
			return o;
		}

		if(typeof n != DATATYPES.TYPE_OBJECT) n = x;
		
		%START_CATCH_ERROR%
		try{
		%STOP_CATCH_ERROR%
			if(typeof XSLTProcessor != DATATYPES.TYPE_UNDEFINED){
				xp = new XSLTProcessor();
				xp.importStylesheet(s);
				o = xp.transformToFragment(n,document);
				if(o && o!= null){
					if(t) o = org.cote.js.xml.serialize(o);
					else o = o.firstChild;
					
				}
			}
	
			else if(typeof DATATYPES.ACTIVEXOBJECT != DATATYPES.TYPE_UNDEFINED && x instanceof DATATYPES.ACTIVEXOBJECT){
				o = new DATATYPES.ACTIVEXOBJECT(org.cote.js.xml.ax_dom_control);
				%START_XML_IETRANSFORM_METHOD_2%
				n.transformNodeToObject(s,o);
				o = o.documentElement;
				%STOP_XML_IETRANSFORM_METHOD_2%
				%START_XML_IETRANSFORM_METHOD_1%
				xp = n.transformNode(s);
				if(t) o = xp;
				else{
					o.loadXML(xp);
					o = o.documentElement;
				}
				%STOP_XML_IETRANSFORM_METHOD_1%

			}
			else{
				_m.sendMessage("Error in transformNode: " + (e.description?e.description:e.message),"512.4",1);
			}
		%START_CATCH_ERROR%
		}
		catch(e){
			_m.sendMessage("Error in transformNode: " + (e.description?e.description:e.message),"512.4",1);
		}
		%STOP_CATCH_ERROR%
		
		return o;

	},
	%STOP_XML_TRANSFORM%

	%START_XML_NAMESPACERESOLVER%
	HashNamespaces:function(){
		var _x = org.cote.js.xml,a,i=0,o;
		_x._xml_namespace_uri = {};
		_x._xml_namespace_url = {};
		for(;i< _x._xml_namespace_resolver.length;i++){
			o = _x._xml_namespace_resolver[i];
			_x._xml_namespace_uri[o[0]]=o[1];
			_x._xml_namespace_url[o[1]]=o[0];
		}
		_x._xml_namespace_hashed=1;
	},
	getURIForURL:function(u){
		var _x = org.cote.js.xml,q;
		if(!_x._xml_namespace_hashed) _x.HashNamespaces();
		q = _x._xml_namespace_url[u];
		return (q?q:"");
	},
	getURLForURI:function(i){
		var _x = org.cote.js.xml,q;
		if(!_x._xml_namespace_hashed) _x.HashNamespaces();
		q = _x._xml_namespace_uri[i];
		return (q?q:"");
	},
	%STOP_XML_NAMESPACERESOLVER%

	lookupNamespaceURI:function(n){
		%START_XML_NAMESPACERESOLVER%
		var _x = org.cote.js.xml;
		if(!_x._xml_namespace_hashed) _x.HashNamespaces();
		if(_x._xml_namespace_uri[n])
			%START_DEBUG_MESSAGE%
			{
			org.cote.js.message.MessageService.sendMessage("Resolving '" + n + "' as '" + _x._xml_namespace_uri[n] + "'","200.1");
			%STOP_DEBUG_MESSAGE%
			return _x._xml_namespace_uri[n];
			%START_DEBUG_MESSAGE%
			}
			else{
				org.cote.js.message.MessageService.sendMessage("Could not resolve '" + n + "'","200.1");
			}
			%STOP_DEBUG_MESSAGE%
		%STOP_XML_NAMESPACERESOLVER%
		return "";
	},
	
	%START_XML_SELECTNODE%
	
	/// <method>
	/// <name>selectSingleNode</name>
	/// <description>Returns a DOM Node selected from the specified document and based on the specified path.</description>
	/// <param name="d" type="XMLDocument">XMLDocument.</param>
	/// <param name="p" type="String">XPath query.</param>
	/// <param name="c" type="DOMNode">Context node.</param>
	/// <return-value name="v" type="String">Returns a DOM Node based on the specified xpath query.</return-value>
	/// </method>
	///	
	selectSingleNode:function(d,x,c){
		/*
			d = XmlDocument
			x = xpath
			c = context node
		*/
		var s,i,n;
		if(typeof d.evaluate != DATATYPES.TYPE_UNDEFINED){
			c = (c ? c : d.documentElement);
			s = d.evaluate(x,c,org.cote.js.xml,0,null);

			return s.iterateNext();
		}
		else if(typeof d.selectNodes != DATATYPES.TYPE_UNDEFINED){
			return (c ? c : d).selectSingleNode(x);
		}

		return 0;
	
	},
	
	/// <method>
	/// <name>selectNodes</name>
	/// <description>Returns an array of DOM Nodes selected from the specified document and based on the specified path.</description>
	/// <param name="d" type="XMLDocument">XMLDocument.</param>
	/// <param name="p" type="String">XPath query.</param>
	/// <param name="c" type="DOMNode">Context node.</param>
	/// <return-value name="aNodes" type="array">Returns an array of DOM Nodes based on the specified xpath query.</return-value>
	/// </method>
	///	
	selectNodes:function(d,x,c){
		/*
			d = XmlDocument
			x = xpath
			c = context node
		*/
		var s,a = [],i,n;
		if(typeof d.evaluate != DATATYPES.TYPE_UNDEFINED){
			c = (c ? c : d.documentElement);
			s = d.evaluate(x,c,org.cote.js.xml,0,null);

			n = s.iterateNext();

			while( typeof n == DATATYPES.TYPE_OBJECT && n != null){
				a[a.length] = n;
				n = s.iterateNext();
			}

			return a;

		}

		else if(typeof d.selectNodes != DATATYPES.TYPE_UNDEFINED){
			return (c ? c : d).selectNodes(x);
		}

		return a;
	
	},
	%STOP_XML_SELECTNODE%	
	
	%START_XML_QUERYNODE%
	/*
		queryNode is useful for light DOM queries when
		XPath is not available, or when querying against an HTML
		DOM for nodes with specific attribute values.
	*/
	
	/// <method>
	/// <name>queryNodes</name>
	/// <description>Returns an array of DOM Nodes selected from the specified document and based on the specified parent node name, node name, and attribute name and values.</description>
	/// <param name="d" type="XMLDocument">XMLDocument.</param>
	/// <param name="p" type="String">Parent element name.</param>
	/// <param name="n" type="String" optional="1" default="null">Element name.  Defaults to parent if not specified.</param>
	/// <param name="a" type="String" optional="1" default="null">Attribute name.</param>
	/// <param name="v" type="String" optional="1" default="null">Attribute value.</param>
	/// <return-value name="aNodes" type="array">Returns an array of DOM Nodes based on the specified parent node name, node name, and attribute name and value.</return-value>
	/// </method>
	///	
	queryNodes:function(x,p,n,a,v){
		return org.cote.js.xml._queryNode(x,p,n,a,v,1);
	},
	
	/// <method>
	/// <name>queryNode</name>
	/// <description>Returns a DOM Node selected from the specified document and based on the specified parent node name, node name, and attribute name and values.</description>
	/// <param name="d" type="XMLDocument">XMLDocument.</param>
	/// <param name="p" type="String">Parent element name.</param>
	/// <param name="n" type="String" optional="1" default="null">Element name.  Defaults to parent if not specified.</param>
	/// <param name="a" type="String" optional="1" default="null">Attribute name.</param>
	/// <param name="v" type="String" optional="1" default="null">Attribute value.</param>
	/// <return-value name="aNodes" type="DOMNode">Returns a DOM Node based on the specified parent node name, node name, and attribute name and value.</return-value>
	/// </method>
	///
	queryNode:function(x,p,n,a,v){
		return org.cote.js.xml._queryNode(x,p,n,a,v,0);
	},
	_queryNode:function(x,p,n,a,v,z){
		/*
			 x = xdom
			 p = parent path
			 n = node path
			 a = attribute name
			 v = attribute value
			 
			 z = node or nodes
		*/

		var i=0,b,e,c,r=[];
		if(!z) r = null;
		
		c = x.getElementsByTagName(p);
		
		if(typeof n==DATATYPES.TYPE_STRING){

			if(!c.length){
				if(!z) return null;
				else return r;
			}
			c = c[0]; 
			e = c.getElementsByTagName(n);
		}
		else e = c;

		
		for(;i<e.length;i++){
			b = e[i];
			if((!a && !v) || (b.getAttribute(a) == v)){
				/*
					single query
				*/
				if(!z){
					r = b;
					break;
				}

				else r[r.length]=b;
				
			}
		}
		return r;
	},
	%STOP_XML_QUERYNODE%
	%START_XML_SERIALIZE_UTILITY%
	
	/// <method>
	/// <name>serialize</name>
	/// <description>Returns a string representation of the specified node and its children.</description>
	/// <param name="n" type="DOMNode">XML DOM Node.</param>
	/// <return-value name="s" type="String">String representation of the specified node.</return-value>
	/// </method>
	///	
	serialize:function(n){
		var v;
		if(typeof XMLSerializer != DATATYPES.TYPE_UNDEFINED){
			return (new XMLSerializer()).serializeToString(n);
		}
		else if(typeof n.xml == DATATYPES.TYPE_STRING){
			return n.xml;
		}
	},
	%STOP_XML_SERIALIZE_UTILITY%
	%START_XML_UTILITIES%
	
	/// <method>
	/// <name>getCDATAValue</name>
	/// <description>Returns a concatenation of all CDATA values that are immediate children of the specified node.</description>
	/// <param name="n" type="DOMNode">XML DOM Node.</param>
	/// <return-value name="v" type="String">Returns a concatenation of all child CDATA values.</return-value>
	/// </method>
	///	
	getCDATAValue:function(n){
		var c,d="",i=0,e;

		if(n == null) return d;

		c = n.childNodes;
		for(;i<c.length;i++){
			e=c[i];
			if(e.nodeName=="#cdata-section") d+=e.nodeValue;
		}
		return d;
	},
	
	/// <method>
	/// <name>getInnerText</name>
	/// <description>Returns a concatenation of text nodes belonging to all children of the specified node.</description>
	/// <param name="n" type="DOMNode">DOM Node.</param>
	/// <return-value name="sTxt" type="String">Returns the inner text of the specified node.</return-value>
	/// </method>
	///	
	getInnerText:function(s){
		var r = "",a,i,e;
		if(typeof s == DATATYPES.TYPE_STRING) return s;
		if(s == null) return r;
		if(typeof s== DATATYPES.TYPE_OBJECT && s.nodeType==3) return s.nodeValue;
		if(s.hasChildNodes()){
			a = s.childNodes;
			for(i=0;i<a.length;i++){
				e = a[i];
				if(e.nodeType==3 || e.nodeType == 4) r+=e.nodeValue;
				if(e.nodeType==1 && e.hasChildNodes()){
					r+=org.cote.js.xml.getInnerText(e);
				}
			}
		}
		return r;
	},
	
	/// <method>
	/// <name>removeChildren</name>
	/// <description>Removes all child nodes of the specified node.</description>
	/// <param name="o" type="DOMNode">DOM Node.</param>
	/// </method>
	///
	removeChildren:function(o){
		var i;
		for(i=o.childNodes.length-1;i>=0;i--)
			o.removeChild(o.childNodes[i]);
		
	},
	
	
/// Prototype for Mozilla
	swapNode : function (n,c){
		if(!n || !c) return;
		if(typeof n.swapNode != DATATYPES.TYPE_UNDEFINED) n.swapNode(c);
		else{
		    var s = n.nextSibling;
			var p = n.parentNode;
			p.replaceChild(n,c);
			p.insertBefore(c, s);
			/*n.parentNode.removeChild(n);*/
		}
	},
	
	/// <method>
	/// <name>setInnerXHTML</name>
	/// <description>Copies the child nodes of the specified source node into the specified target node.</description>
	/// <param name="t" type="DOMNode">DOM Node into which the source node children will be copied.</param>
	/// <param name="s" type="DOMNode">DOM Node from which nodes will be copied into the target node.</param>
	/// <param name="p" type="boolean" optional="1" default = "false">Bit indicating whether to keep the children of the target node, or to remove them before copying in the new contents.</param>
	/// <param name="d" type="Document" optional="1" default = "window.document">Document object to use when creating elements for the target node.</param>
	/// <param name="z" type="boolean" optional = "1" default = "false">Bit indicating whether recursion should be blocked.</param>
	/// <param name="c" type="boolean" optional = "1" default = "false">Bit indicating whether whitespace should be preserved.</param>
	/// <param name="h" type="boolean" optional = "1" default = "false">Bit indicating whether HTML source nodes should be cloned instead of incrementally recreated.</param>
	/// <param name="ch" type="function" optional = "1" default = "false">Optional callback handler for substituting values prior to copying.  Useful for templates.</param>
	/// <return-value name="v" type="variant">Depending on the type of copy operation, returns a reference to the newly created node.</return-value>
	/// </method>
	///
	setInnerXHTML:function(t,s,p,d,z,c,h,ch){
		/*
			t = target
			s = source
			p = preserve
			d = target document object
			z = no recursion
			
			c = preserve whitespace
			
			h = html refactor ; clone the node instead of creating the element and copy attributes
			
			
			
			r = return node reference
		*/
		var y,e,a,l,x,n,v,r = 0,b,f;
		
		/* typeof d == DATATYPES.TYPE_UNDEFINED */
		if(!d) d = document;
		
		b = (d == document?1:0);
		
		if(!p)
			org.cote.js.xml.removeChildren(t);
		

		y=(s && typeof s==DATATYPES.TYPE_OBJECT)?s.nodeType :(typeof s==DATATYPES.TYPE_STRING)?33:-1;
		%START_CATCH_ERROR%
		try{
		%STOP_CATCH_ERROR%
		switch(y){
			case 1:
				if(h){
					e = s.cloneNode(false);
				}
				else{
				    f = s.nodeName;
				    if(typeof ch == DATATYPES.TYPE_FUNCTION) f = ch(y,f);
				    if(!f) return 0;
					e=d.createElement(f);
					a=s.attributes;
					l=a.length;
					for(x=0;x<l;x++){
						n=a[x].nodeName;
						v=a[x].nodeValue;
    				    if(typeof ch == DATATYPES.TYPE_FUNCTION){
    				        n = ch(2,n);
    				        v = ch(2,v);
    				    }
	
						/*
							Must check for d == document to make sure whether this is the HTML DOM or not, because
							these cases only apply to IE oddness in the HTML DOM, not the XML DOMs.
						*/
						/* stupid IE */
						if(b && n=="style"){
							e.style.cssText=v;
						}
						/* stupid IE */
						else if(b && n=="id"){
							e.id=v;
						}
	
						/* stupid IE */
						/*  && org.cote.js.dom.browser.client.bswitch==1){ */
						else if(b && n=="class"){
							e.className=v;
						}
	
						/* stupid IE */
						else if(b && n.match(/^on/i)){
							eval("e." + n + "=function(){" + v  +"}");
						}
						else{
							e.setAttribute(n,v);
						}
					}
				}
				if(!z && s.hasChildNodes()){
					a=s.childNodes;
					l=a.length;
					for(x=0;x<l;x++)
						org.cote.js.xml.setInnerXHTML(e,a[x],1,d,z,c,h,ch);
					
				}

				/* stupid IE */
				if(b && s.nodeName.match(/input/i) && org.cote.js.IsAttributeSet("checked")){
					e.checked=true;
				}

				t.appendChild(e);
				r = e;
				break;
			case 3:
				e=s.nodeValue;
    		    if(typeof ch == DATATYPES.TYPE_FUNCTION) e = ch(y,e);
				if(e){
/*
					e=e.replace(/^\s* /,"");
					e=e.replace(/\s*$/,"");
*/
					e=e.replace(/\s+/g," ");
					t.appendChild(d.createTextNode(e));
					r = e;
				}
				break;
			/* CDATA */
			case 4:
				try{
				e = s.nodeValue;
				if(typeof ch == DATATYPES.TYPE_FUNCTION) e = ch(y,e);
				t.appendChild(d.createCDATASection(e));
				}
				catch(er){ alert(e + "\n" + ch + "\n" + t.nodeName);}
				break;
			case 8:
				/*
					Ignore comments
				*/
				break;
			case 33:
				e=s;
				if(typeof ch == DATATYPES.TYPE_FUNCTION) e = ch(y,e);
				if(e){
					if(!c){
						e=e.replace(/^\s*/,"");
						e=e.replace(/\s*$/,"");
						e=e.replace(/\s+/g," ");
					}
					t.appendChild(d.createTextNode(e));
					r = e;
				}
				break;
			default:
				%START_DEBUG_MESSAGE%
				org.cote.js.message.MessageService.sendMessage("Skip node type: " + y,"200.1");
				%STOP_DEBUG_MESSAGE%
				break;
		}
		%START_CATCH_ERROR%
		}
		catch(e){
			org.cote.js.message.MessageService.sendMessage( (e.message ? e.message : e.description) + " in type " + y + " : " + org.cote.js.error.traceRoute(org.cote.js.xml.setInnerXHTML),"200.4");
		}
		%STOP_CATCH_ERROR%
		return r;
	},
	%STOP_XML_UTILITIES%

	/* stub is used for swapping handlers on IE */	
	_stub:function(){
		/* do nothing */
	},
	
	StaticInitialize:function(){
		org.cote.js.message.MessageService.subscribe(org.cote.js.xml,"destroy","_handle_destroy");
		org.cote.js.xml.si = 1;
	},
	
	_handle_destroy:function(s, v){
		
		var _x = org.cote.js.xml;
		
		org.cote.js.message.MessageService.unsubscribe(org.cote.js.xml,"destroy","_handle_destroy");

		%START_XML_CACHE%
		_x.clearCache();
		%STOP_XML_CACHE%
		
		%START_XML_POOL%

		%STOP_XML_POOL%
		
		_x._xml_requests = [];
		_xml_requests_map = [];	
		_x._xml_http_pool_created = 0;
		_x._xml_http_object_use = 0;
		_x._xml_http_objects=[];

	},

	/// <method internal = "1">
	/// <name>JSONReviver</name>
	/// <description>Custom reviver for handling date values.</description>
	/// <param name="k" type="String">Key name.</param>
	/// <param name="v" type="String">Key value.</param>
	/// <return-value name="r" type="String">Revived key value for use with JSON.</return-value>
	/// </method>
	///
	JSONReviver : function (k, v) {
		var a;
		if( typeof v == "string" && (a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(v)))
			return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],+a[5], +a[6]));
		return v;
	}
};

/// </static-class>
/// </package>
/// </source>
///
